﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SkyBase
{
    abstract class Overlay
    {
        public float layer { get; set; }

        //Overlay will not be removed without this being enabled to true
        public bool readyForRemoval { get { return _readyForRemoval; } }
        private bool _readyForRemoval = false;
        //Specifies whether we should pause the game or not while this interface is active
        public bool hold = false;

        //Optional name for the overlay
        public string name;

        //Alpha values used for transparency
        protected float alpha = 1f;

        //Determines whether the window should fade in/out or not
        private bool fade;

        //The background texture of the overlay
        protected Texture2D background;
        protected Rectangle bounds;


        public Overlay(Texture2D background, String name = null, bool fade = false)
        {
            layer = 0.2f;
            this.background = background;
            bounds = new Rectangle(0, 0, background.Width, background.Height);
            if (name != null)
                this.name = name;
            else
                this.name = "Overlay";
            if (fade)
            {
                this.fade = true;
                alpha = 0f;
            }
        }


        public virtual void Draw(SpriteBatch spriteBatch, Vector2 cameraPos)
        {
            if (fade && alpha < 1)
                alpha += 0.1f;

            Rectangle tempBounds = bounds;
            tempBounds.X = (int)cameraPos.X;
            tempBounds.Y = (int)cameraPos.Y;
            spriteBatch.Draw(background, tempBounds, null, Color.White * alpha, 0, new Vector2(0, 0), SpriteEffects.None, layer);
        }

        public abstract void Update(GameTime gameTime);

        /// <summary>
        /// This method is supposed to do stuff before readyForRemoval gets set to true.
        /// Override this if your overlay needs to do stuff before it gets removed.
        /// NEVER SET readyForRemoval
        /// </summary>
        public virtual void preRemove()
        {
            if (fade && alpha > 0)
            {
                alpha -= 0.2f;
            }
            else
                _readyForRemoval = true;
        }


        /// <summary>
        /// This method prepares the overlay to be displayed again.
        /// If you have any specific variables that need to be reset, extend this method!
        /// </summary>
        public virtual void reset()
        {
            _readyForRemoval = false;
        }
    }
}
